<template>
  <view class="group-lottery">
    <view class="top-silter">
      <view class="silde">
        <image class="silde-img" :src="silter_1" />
        <image class="silde-img" :src="silter_1" />
      </view>
    </view>

    <view class="btn-main">
      <view
        class="lottery-btn"
        hover-class="hover-bubble"
        @tap="onClickOperate($event, 'lottery', details[item])"
        v-for="(item, index) in btnTypeList"
        :key="index"
      >
        <image class="bg-icon" :src="btnList[index]" />
        <view class="lottery-text">
          <view class="text">
            {{ details[item].label }}
          </view>
          <view class="price-1"> ￥{{ details[item].price }} </view>
        </view>
      </view>
    </view>
    <view class="todo"> *商品抽奖存在概率性，付费请谨慎* </view>
  </view>
</template>
<script>
import one_img from '../img/one-0.png';
import five_img from '../img/five-0.png';
import ten_img from '../img/ten-0.png';
import all_img from '../img/all-0.png';
import silter_1 from '../img/silter-1.png';

import tools from '@/shopro/utils/tools';
const _delay = tools.delayDither(100);
export default {
  // 建议 创建每个组件时 都添加name属性 标识组件名称
  name: '',
  components: {},
  props: {
    details: {
      type: Object,
      default: () => ({}),
    },
  },
  data: () => ({
    silter_1,
    btnTypeList: ['single', 'five', 'ten', 'all'],
    btnList: [one_img, five_img, ten_img, all_img],
  }),
  // 计算属性 适配者模式
  computed: {},
  // 数据监听
  watch: {},
  /**
   * 生命周期 类似 发布订阅者模式
   * 在实例初始化之前被调用
   */
  beforeCreate() {},
  // 在实例创建完成后被立即调用
  created() {},
  // 在挂载开始之前被调用
  beforeMount() {},
  // 挂载到实例上去之后调用。详见 注意：此处并不能确定子组件被全部挂载，如果需要子组件完全挂载之后在执行操作可以使用nextTick
  mounted() {},
  // 数据更新时调用，发生在虚拟 DOM 打补丁之前
  beforeUpdate() {},
  // 由于数据更改导致的虚拟 DOM 重新渲染和打补丁，在这之后会调用该钩子
  updated() {},
  // 实例销毁之前调用。在这一步，实例仍然完全可用
  beforeDestroy() {},
  // Vue 实例销毁后调用。调用后，Vue 实例指示的所有东西都会解绑定，所有的事件监听器会被移除，所有的子实例也会被销毁。
  destroyed() {},
  methods: {
    /**
     *  页面点击事件 防抖
     * @param {Object} ev  $event
     * @param {String} name 执行名称
     * @param {Object} data 传值
     */
    onClickOperate(ev, name, data = {}) {
      _delay(() => {
        switch (name) {
          case 'lottery':
            this.clickLottery(data);
            break;
        }
      }, false);
    },

    clickLottery(ev) {
      this.$emit('lottery', { data: ev });
    },
  },
};
</script>
<style lang="scss" scoped>
view,
image {
  max-width: none;
}
.group-lottery {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 20;
  padding: 24rpx;
  width: 100%;
  height: 160rpx;
  background-color: #fff;
  animation: slide-in-bottom 1s linear 0s 1 normal none;
  .todo {
    margin-top: 10rpx;
    text-align: center;
    font-size: 16rpx;
    font-weight: 800;
    color: rgba(0, 0, 0, 0.4);
  }
  .btn-main {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .lottery-btn.disabled {
      filter: grayscale(100%);
    }
    .lottery-btn {
      position: relative;
      width: 154rpx;
      height: 76rpx;

      .bg-icon {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
      }
      .lottery-text {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;

        position: relative;
        top: -1px;
        z-index: 1;
        width: 100%;
        height: 100%;
        .text {
          font-size: 26rpx;
          line-height: 25rpx;
          font-weight: 800;
          color: #fff;
        }
        .price-1 {
          margin-top: 4rpx;
          font-size: 22rpx;
          line-height: 21rpx;
          font-weight: 800;
          color: #fff;
        }
      }
    }
  }

  .top-silter {
    position: absolute;
    top: -30rpx;
    left: 0;
    width: 100%;
    height: 33rpx;
    background: #0c1323;
    overflow: hidden;
    .silde {
      display: inline-flex;
      height: 33rpx;
      animation: slide-in-left var(--yfs-silde-time) linear 0s infinite normal
        none;
      .silde-img {
        width: 100vw;
        height: 33rpx;
      }
    }
  }
}
@keyframes slide-in-left {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}
</style>
